package com.google.code.jmarias.common.action;

import com.google.code.jmarias.common.AbstractUser;
import com.google.code.jmarias.common.Card;
import com.google.code.jmarias.common.NewPlayer;
import com.google.code.jmarias.common.NewTable;
import java.util.Arrays;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Ondrej Michal
 */
@XmlRootElement
public class DealFiveCardsAction extends GameAction {

    private Card[] cards;
    private AbstractUser recipient;

    public DealFiveCardsAction() {
    }

    public DealFiveCardsAction(Card[] cards, AbstractUser recipient) {
        if (cards.length != 5) {
            throw new IllegalArgumentException("Given cards count is " + cards.length);
        }
        this.cards = cards;
        this.recipient = recipient;
    }

    @Override
    public void updateTable(NewTable table, AbstractUser user) {
        for (NewPlayer player : table.getPlayers()) {
            if (player.getClient().equals(recipient)) {
                for (Card card : cards) {
                    player.addToHand(card);
                }
            }
        }
    }

    @Override
    public String toString() {
        String info = "";
        if (cards != null) {
            info = Arrays.asList(cards).toString();
        }
        return "Hraci " + recipient + " rozdano 5 karet " + info;
    }

    public Card[] getCards() {
        return cards;
    }

    public void setCards(Card[] cards) {
        this.cards = cards;
    }

    public AbstractUser getRecipient() {
        return recipient;
    }

    public void setRecipient(AbstractUser recipient) {
        this.recipient = recipient;
    }

}
